<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Paginator;

class Index extends Controller
{
    public function index()
    {
		$cat = Db::table('ims_ewei_shop_category')->where('parentid<>0 and uniacid=7')->select();
		foreach($cat as $k=>$v){
			$cat[$k]['pro'] =  Db::table('ims_ewei_shop_goods')->where("ccate={$v['id']} and uniacid=7")->order('id desc')->limit(8)->select();
		}
		$this->assign('cat',$cat);
		return view();
	}
	//产品列表
	public function prolist($cid = 0)
	{
		if($cid){
			$ccate = Db::table('ims_ewei_shop_category')->where("id=$cid")->find();
			$ccate['firstcat'] = Db::table('ims_ewei_shop_category')->where("id={$ccate['parentid']}")->value('name');
			$acat = Db::table('ims_ewei_shop_category')->where("parentid={$ccate['parentid']}")->select();
			$goods = Db::table('ims_ewei_shop_goods')->where("ccate = $cid")->paginate(24);
			$this->assign('goods',$goods);
			$this->assign('acat',$acat);
			$this->assign('ccate',$ccate);
		}else{
			exit('分类不存在！');
		}
		return view();
	}
	//产品详情
	public function goods($gid=0)
	{
		
		if($gid){
			$goods = Db::table('ims_ewei_shop_goods')->where("id = $gid")->find();
			$goods['firstcat'] = Db::table('ims_ewei_shop_category')->where("id={$goods['pcate']}")->value('name');
			$goods['subcat'] = Db::table('ims_ewei_shop_category')->where("id={$goods['ccate']}")->value('name');
			$acat = Db::table('ims_ewei_shop_category')->where("parentid={$goods['pcate']}")->select();
			$goods['images'] = unserialize($goods['thumb_url']);
			$goods['jif'] = $goods['sfjf'] * $goods['marketprice'];
			$this->assign('goods',$goods);
			$this->assign('acat',$acat);
		}else{
			exit('商品不存在！');
		}
		return view();
	}
}
